<?php
include("general_include.php");
include "checklogin.php";
		$Search_lesson_title = $Search_lesson_title=='Search by title'?'':$Search_lesson_title;
		/*$Search_student_id = $Search_student_id;
		$Search_lesson_status = $Search_lesson_status;
		$Search_from_date = $Search_from_date=='Search From'?'':$Search_from_date;
		$Search_to_date = $Search_to_date=='Search To'?'':$Search_to_date;*/
		
		if(!empty($Search_lesson_title))
		{
			$searchSql =  $searchSql." AND lesson_title like '%".trim(mysql_quote($Search_lesson_title,"N"))."%'"; 
		}
		
		/*if(!empty($Search_student_id))
		{
			 $searchSql =  $searchSql." AND student_id=".$Search_student_id; 
		}
		
		if(!empty($Search_lesson_status))
		{
			 $searchSql =  $searchSql." AND lesson_status_id=".$Search_lesson_status; 
		}
		
		if(!empty($Search_from_date))
		{
			 $searchSql =  $searchSql." AND date_added >= '".mysql_quote($Search_from_date,"N")."'"; 
		}
		
		if(!empty($Search_to_date))
		{
			 $searchSql =  $searchSql." AND date_added <= '".mysql_quote($Search_to_date,"N")."'"; 
		}*/
		

$CoachgameSql = "SELECT * FROM ".TABLEPREFIX."_lesson WHERE coach_id=".$_SESSION['user_id'].$searchSql." ORDER BY date_added DESC";
$CoachgameArr = $UserManagerObjAjax->GetRecords("All",$CoachgameSql);

$Numcoachgame=count($CoachgameArr);

for($g=0;$g<$Numcoachgame;$g++)
{
	$CoachgameArr[$g]['date_added'] = $CoachgameArr[$g]['date_added'];
	$CoachgameArr[$g]['lesson_id'] = $CoachgameArr[$g]['lesson_id'];
	$CoachgameArr[$g]['lesson_title'] = $CoachgameArr[$g]['lesson_title'];
	$CoachgameArr[$g]['student_id'] = $CoachgameArr[$g]['student_id'];
	
	$Sql_Name="SELECT name FROM ".TABLEPREFIX."_user WHERE user_id=".$CoachgameArr[$g]['student_id'];
	$Sql_NameArr = $UserManagerObjAjax->GetRecords("Row",$Sql_Name);
	
	$CoachgameArr[$g]['student_name'] = $Sql_NameArr['name'];
	$CoachgameArr[$g]['lesson_price'] = $CoachgameArr[$g]['lesson_price'];
	$CoachgameArr[$g]['lesson_commision_admin'] = $CoachgameArr[$g]['lesson_commision_admin'];
	
	$CoachgameArr[$g]['my_commision'] = $CoachgameArr[$g]['lesson_price']*(1-($CoachgameArr[$g]['lesson_commision_admin']/100));
	
	$CoachgameArr[$g]['lesson_status_id'] = $CoachgameArr[$g]['lesson_status_id'];
	
	$Sql_Status="SELECT lesson_status_title FROM ".TABLEPREFIX."_lesson_status WHERE lesson_status_id=".$CoachgameArr[$g]['lesson_status_id'];
	$Sql_StatusArr = $UserManagerObjAjax->GetRecords("Row",$Sql_Status);
	
	$CoachgameArr[$g]['lesson_status'] = $Sql_StatusArr['lesson_status_title'];
}

/* Student Record */
$StudentRecSql="SELECT student_id FROM ".TABLEPREFIX."_lesson WHERE coach_id=".$_SESSION['user_id'];
$StudentRecArr=$UserManagerObjAjax->GetRecords("All",$StudentRecSql);
for($i=0;$i<count($StudentRecArr);$i++)
{
$SelectStudentArr[$i]['student_id'] = $StudentRecArr[$i]['student_id'];

$StudentSql="SELECT name FROM ".TABLEPREFIX."_user WHERE user_id=".$SelectStudentArr[$i]['student_id'];
$StudentName = $UserManagerObjAjax->GetRecords("Row",$StudentSql);

$SelectStudentArr[$i]['student_name'] 	= $StudentName['name'];
}	
/* Student Record */

/* Status Record */
$StatusRecSql="SELECT lesson_status_id,lesson_status_title FROM ".TABLEPREFIX."_lesson_status ";
$StatusRecArr=$UserManagerObjAjax->GetRecords("All",$StatusRecSql);
for($i=0;$i<count($StatusRecArr);$i++)
{
$SelectStatusArr[$i]['lesson_status_id'] = $StatusRecArr[$i]['lesson_status_id'];
$SelectStatusArr[$i]['lesson_status_title']	= $StatusRecArr[$i]['lesson_status_title'];
}	
/* Status Record */
$smarty->assign('SelectStudentArr',$SelectStudentArr);
$smarty->assign('SelectStatusArr',$SelectStatusArr);
$smarty->assign("Search_lesson_title",$Search_lesson_title);

$smarty->assign('Numcoachgame',$Numcoachgame);
$smarty->assign('CoachgameArr',$CoachgameArr);


?>